package com.annotation.packageDemo;

import java.lang.reflect.Method;

/**
 * isAnnotationPresent demo
 */
public class PackageDemo {
	
	@Demo(str = "Demo Annotation", val = 100) //// set values for the annotation
	public static void example() { //// a method to call in the main
		PackageDemo ob = new PackageDemo();
		try {
			Class c = ob.getClass();
			Method m = c.getMethod("example");			//  // get the method example
			Demo annotation = m.getAnnotation(Demo.class);	// get the annotation for class Demo
			System.out.println(annotation.str() + " " + annotation.val());// print the annotation
			
		} catch (NoSuchMethodException exc) {
			exc.printStackTrace();
		}
	}

	public static void main(String args[]) throws ClassNotFoundException {
		example();
		
		Class cls = Class.forName("java.io.LineNumberInputStream");
        Class cls2 = Class.forName("java.lang.Deprecated");
        System.out.println("isAnnotationPresent  : " + cls.isAnnotationPresent(cls2));  //如果注解类是当前类的注解，返回true；否则返回false
		
		Package[] pack = Package.getPackages();
		for (int i = 0; i < pack.length; i++) {//	// check if annotation hello exists
			System.out.println("" + pack[i].isAnnotationPresent(Demo.class));
		}
	}
}
